<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("../conn.php");
$db = new DBC();

$code = "";
$name = "";
$url = "";
$validateDays = "";
$price = "";
if (isset($_GET['code'])) {
    $sql = "SELECT * FROM t_hibaby_property WHERE code = " . $_GET['code'];
    $data = $db->fetchData($sql);
    if (count($data) > 0) {
        $code = $data[0]['code'];
        $name = $data[0]['name'];
        $url = $data[0]['url'];
        $price = $data[0]['price'];
        $validateDays = $data[0]['validateDays'];
        $isModify = 1;
    }
} else {
    $isModify = 0;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #CCCCCC;
            }

            .text{
                height:20px;
            }
            .disable{
                background-color:#CCCCCC;
            }
            -->
        </style>
        <script language="javascript">
            function onSubmitCheck(){
                var code = document.getElementById("code").value;
                var name = document.getElementById("name").value;
                var price = document.getElementsByName("price");
                var validateDays = document.getElementById("validateDays").value;
                var url = document.getElementById("url").value;
                var isok = true;

                if(code==""){
                    alert("\u8bf7输入编码");
                    isok = false;
                }else if(name==""){
                    alert("\u8bf7输入名称");
                    isok = false;
                }else if(price==""){
                    alert("\u8bf7输入价格");
                    isok = false;
                }else if(url==""){
                    alert("\u8bf7输入资源地址");
                    isok = false;
                }else if(validateDays==""){
                    alert("\u8bf7输入有效天数");
                    isok = false;
                }
                if(!isok){
                    event.returnValue = false;
                }
            }
        </script>
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#age").change(function(){
                    $.get("getPackByAge.php?age=1", function(data){
                        var obj = jQuery.parseJSON(data);
                        $('#packselect').children().remove().end();
                        $("#packselect").append('<option value="-1">\u65e0</option>');
                        for(var i=0;i<obj.length;i++){
                            var option = "<option value="+obj[i].packid+">"+obj[i].packcode+"-"+obj[i].name+"</option>";
                            $("#packselect").append(option);
                        }
                    });
                });
            });
        </script>
    </head>

    <body>
        <?php
        if (!isset($code)) {
            $code = "";
        }
        if (!isset($name)) {
            $name = "";
        }
        if (!isset($url)) {
            $url = "";
        }
        if (!isset($price)) {
            $price = "";
        }
        if (!isset($validateDays)) {
            $validateDays = "";
        }
        ?>
        <br/>
        <form id="form1" name="form1" method="post" action="property.action.php" enctype="multipart/form-data">
            <table width="50%" border="0" align="center" cellpadding="1" cellspacing="1">
                <tr>
                    <td height="30" bgcolor="#666666">道具编号<input name="isModify" type="hidden" value="<?php echo $isModify; ?>" /></td>
                    <td bgcolor="#9999FF"><input id="code" name="code" type="text" size="50" class="text"  value="<?php echo $code; ?>" <?php if ($isModify) { echo "disabled=\"disabled\"";} ?> /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">道具名称</td>
                    <td bgcolor="#9999FF"><input id="name" name="name" type="text" size="50" class="text" value="<?php echo $name; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">原价</td>
                    <td bgcolor="#9999FF"><input id="price" name="price" type="text" size="10" class="text" value="<?php echo $price; ?>"/> <font color="red">只能输入数字</font></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">有效天数</td>
                    <td bgcolor="#9999FF"><input id="validateDays" name="validateDays" type="text" size="10" class="text" value="<?php echo $validateDays; ?>"/> <font color="red">只能输入数字</font></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">资源地址</td>
                    <td bgcolor="#9999FF"><input id="url" name="url" type="text" size="50" class="text" value="<?php echo $url; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">&nbsp;</td>
                    <td bgcolor="#9999FF">
                        <input type="submit" name="Submit" value="提交" onclick="onSubmitCheck()" />                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
<?php

function has($type, $num) {
    if (strpos($type, $num) >= 0) {
        return true;
    }
    return false;
}

include_once '../footer.php';
//} else {
//    header("login.php");
//}
?>
